<template>
  <div class="container">
    <OlArc ref="OlArcRef"></OlArc>
    <div class="count">
      <div class="item" style="padding-top: 16px;">
        <div class="title">
          <img src="../../static/images/icon-beijiang.png" alt="">
          <div>北江船闸数<span class="total">共<span style="color: #165DFF;">{{ beijiangData.totalNum }}</span>个</span></div>
        </div>
        <div class="details">
          <div class="sub-item" style="width: 33.3%;border-right: 1px solid #F0F0F0;">
            <div class="bj-value">{{ beijiangData.three }}</div>
            <div class="bj-name">Ⅲ级</div>
          </div>
          <div class="sub-item" style="width: 33.3%;border-right: 1px solid #F0F0F0;">
            <div class="bj-value">{{ beijiangData.four }}</div>
            <div class="bj-name">Ⅳ级</div>
          </div>
          <div class="sub-item" style="width: 33.3%;">
            <div class="bj-value">{{ beijiangData.five }}</div>
            <div class="bj-name">Ⅴ级</div>
          </div>
        </div>
      </div>
      <div class="item" style="padding-top: 16px;padding-bottom: 16px;">
        <div class="title">
          <img src="../../static/images/icon-lianjiang.png" alt="">
          <div>连江船闸数<span class="total">共<span style="color: #F17665;">{{ lianjiangData.totalNum }}</span>个</span></div>
        </div>
        <div class="details">
          <div class="sub-item" style="width: 50%;border-right: 1px solid #F0F0F0;">
            <div class="lj-value">{{ lianjiangData.four }}</div>
            <div class="lj-name">Ⅳ级</div>
          </div>
          <div class="sub-item" style="width: 50%;">
            <div class="lj-value">{{ lianjiangData.six }}</div>
            <div class="lj-name">Ⅵ级</div>
          </div>
        </div>
      </div>      
    </div>
    <div class="left-part">
      <div class="item">
        <img src="../../static/images/icon-filter.png" @click="showFilter = true">
      </div>
      <div class="item">
        <img src="../../static/images/icon-statistic.png" @click="handleGo">
      </div>
    </div>
    <div class="right-part">     
      <div class="content">
        <div class="legend">          
          <div class="legend-item">
            <img src="../../static/images/icon-beijiang.png" alt="">
            <div>北江船闸</div>
          </div>  
          <div class="legend-item">
            <img src="../../static/images/icon-lianjiang.png" alt="">
            <div>连江船闸</div>
          </div>    
        </div> 
      </div>          
    </div>
    <div class="tianqi" @click="gotoWeather">
      <img src="../../static/images/tianqi.png">
    </div>   
    <!-- 筛选弹窗 -->
    <van-popup
      v-model:show="showFilter"
      round
      closeable
      position="bottom"
      :style="{ height: '40%' }"
      class="filter-popup"
    >
      <div class="filter-title">筛选</div>
      <div class="filter-content">
        <div class="item">
          <div class="item-title">船闸等级</div>
          <div class="item-content">
            <div :class="checkedValues1.indexOf('Ⅲ级')!=-1?'active':''" @click="handleCheckedValues1('Ⅲ级')">Ⅲ级</div>
            <div :class="checkedValues1.indexOf('Ⅳ级')!=-1?'active':''" @click="handleCheckedValues1('Ⅳ级')">Ⅳ级</div>
            <div :class="checkedValues1.indexOf('Ⅴ级')!=-1?'active':''" @click="handleCheckedValues1('Ⅴ级')">Ⅴ级</div>
            <div :class="checkedValues1.indexOf('Ⅵ级')!=-1?'active':''" @click="handleCheckedValues1('Ⅵ级')">Ⅵ级</div>
            <!-- <van-checkbox-group v-model="checkedValues1" direction="horizontal">
              <van-checkbox name="Ⅲ级">Ⅲ级</van-checkbox>
              <van-checkbox name="Ⅳ级">Ⅳ级</van-checkbox>
              <van-checkbox name="Ⅴ级">Ⅴ级</van-checkbox>
              <van-checkbox name="Ⅵ级">Ⅵ级</van-checkbox>
            </van-checkbox-group> -->
          </div>
        </div>
        <div class="item">
          <div class="item-title">所在航道</div>
          <div class="item-content">    
            <div :class="checkedValues2.indexOf('北江')!=-1?'active':''" @click="handleCheckedValues2('北江')">北江</div>
            <div :class="checkedValues2.indexOf('连江')!=-1?'active':''" @click="handleCheckedValues2('连江')">连江</div>    
            <!-- <van-checkbox-group v-model="checkedValues2" direction="horizontal">
              <van-checkbox name="北江">北江</van-checkbox>
              <van-checkbox name="连江">连江</van-checkbox>
            </van-checkbox-group> -->
          </div>
        </div>
        <div class="item">
          <div class="item-title">所属辖区</div>
          <div class="item-content">
            <div :class="checkedValues3.indexOf('韶关')!=-1?'active':''" @click="handleCheckedValues3('韶关')">韶关</div>
            <div :class="checkedValues3.indexOf('清远')!=-1?'active':''" @click="handleCheckedValues3('清远')">清远</div>    
            <!-- <van-checkbox-group v-model="checkedValues3" direction="horizontal">
              <van-checkbox name="韶关">韶关</van-checkbox>
              <van-checkbox name="清远">清远</van-checkbox>
            </van-checkbox-group> -->
          </div>
        </div>  
      </div>
      <div class="sure-btn" @click="handleSure">确定</div>
    </van-popup>
  </div>
</template>

<script setup>
  import { ref, reactive, onMounted, nextTick } from 'vue';
  import { useRouter } from "vue-router";
  const router = useRouter();
  
  //地图
  import OlArc from "./olArc.vue"; 

  // 引入api
  import {
    screenMapData,
  } from "@/bridge-h5/utils/myapi";
  const showCountDetails = ref(false);

  const OlArcRef = ref(null);
  //筛选
  const showFilter = ref(false);
  const checkedValues1 = ref([]);
  const checkedValues2 = ref([]);
  const checkedValues3 = ref([]);
  const handleCheckedValues1 = (val) => {
    if (checkedValues1.value.indexOf(val) != -1) {
      checkedValues1.value.splice(checkedValues1.value.indexOf(val), 1);
    } else {
      checkedValues1.value.push(val);
    }
  };
  const handleCheckedValues2 = (val) => {
    if (checkedValues2.value.indexOf(val) != -1) {
      checkedValues2.value.splice(checkedValues2.value.indexOf(val), 1);
    } else {
      checkedValues2.value.push(val);
    }
  };
  const handleCheckedValues3 = (val) => {
    if (checkedValues3.value.indexOf(val) != -1) {
      checkedValues3.value.splice(checkedValues3.value.indexOf(val), 1);
    } else {
      checkedValues3.value.push(val);
    }
  };

  const handleSure = () => {    
    OlArcRef.value.initMap({
      slLevel: checkedValues1.value.join(','),
      hangdao: checkedValues2.value.join(','),
      block: checkedValues3.value.join(',')
    });
    showFilter.value = false;
  };

  //基本情况
  const beijiangData = ref({});
  const lianjiangData = ref({});
  const countDataFn = () => {
    screenMapData().then((res) => {
      if(res.code === 200){
        beijiangData.value = res.data[0].beijiang;
        lianjiangData.value =  res.data[0].lianjiang;
      }
    });
  };
  

  //跳转到统计分析
  const handleGo = () => {
    router.push({
      path: "/statisticalAnalysis",
      query: {},
    });
  };

  //跳转到气象统计
  const gotoWeather = () => {
    router.push({
      path: "/weather",
      query: {},
    });
  };

  onMounted(() => {
    document.title = "闸坝智能调度与安全监测";
    countDataFn();
  });
</script>

<style lang="scss" scoped>
  .container{
    position: relative;
    height: 100%;
    .left-part{
      width: 36px;
      height: 76px;
      position: absolute;
      top: 32px;
      left: 20px;
      background: #FFFFFF;
      box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.08);
      border-radius: 8px;
      opacity: 1;
      .item{
        padding: 6px 0;
        margin: 0 6px;        
        img{
          width: 24px;
          height: 24px;
        }
        &:first-child{
          border-bottom: 1px solid rgba(0,0,0,0.15);
        }
      }
    }
    .count{
      position: absolute;
      bottom: 0;      
      width: 100%;
      background-color: #fff;    
      .item{        
        padding: 0px 20px;
        .title{
          display: flex;
          align-items: center;
          color: #262626;
          font-size: 14px;
          font-weight: bold; 
          line-height: 19px;
          img{
            width: 14px;
            height: 19px;
            padding-right: 4px;
          }        
          .total{
            color: #595959;
            font-size: 12px;
            padding-left: 4px;
          }
        }
        .details{
          display: flex;
          justify-content: space-around;
          align-items: center;
          background-color: #F8F9FB;
          margin-top: 6px;
          .sub-item{
            // width: 25%;
            margin: 2px 0;
            text-align: center;
            .bj-value{
              font-size: 18px;
              font-weight: bold;
              color: #165DFF;
            }
            .bj-name{
              font-size: 12px;
              color: #595959;
            }
            .lj-value{
              font-size: 18px;
              font-weight: bold;
              color: #F17665;
            }
            .lj-name{
              font-size: 12px;
              color: #595959;
            }
          }
        }
      }
    }
    .right-part{
      .spread{
        position: absolute;
        top: 36px;
        right: 0;
      } 
      .content{
        position: absolute;
        left: 20px;
        bottom: 190px;
        background: #fff;
        box-shadow: 0px 2px 4px 0px rgba(4,44,136,0.1);
        border-radius: 8px;
        .legend{
          width: 88px;       
          .legend-item{
            display: flex;
            // align-items: center;
            margin: 8px 0px 8px 10px;
            font-size: 12px;
            font-weight: 400;
            color: #595959;
            img{
              padding-right: 4px;
            }
          }
        }
      }          
    }
    .filter-popup{
      .filter-title{
        text-align: center;
        font-size: 18px;
        font-weight: bold;
        color: #262626;
        margin-top: 12px;
      }
      .filter-content{
        margin: 18px 0px 0px 18px;
        .item{
          .item-title{
            font-size: 16px;
            font-weight: 400;
            color: #000000;
          }
          .item-content{
            display: flex;
            margin: 8px 0;   
            font-size: 12px;
            font-weight: 400;
            color: #595959;    
            div{
              width: 25%;
              border: 1px solid #D9D9D9;    
              border-radius: 8px;
              padding: 4px 0px;
              text-align: center;
              margin-right: 8px;
            }
            .active{
              color: #266FE8;
              border: 1px solid #266FE8;
              border-radius: 8px 8px 8px 8px;
            }                     
          }

        }        
      }
      .sure-btn{      
        text-align: center;
        color: #fff;
        background-color: #165DFF;
        padding: 10px 0;
        margin: 10px 20px;
        border-radius: 8px;
      }
    }
    .tianqi{
      position: absolute;
      right: 20px;
      bottom: 180px;
      img{
        width: 40px;
        height: 40px;
      }
    }
  }
</style>